package com.g001.model.powers;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

import com.g001.enums.BlockType;
import com.g001.enums.MessagePositionType;
import com.g001.model.GCharacter;
import com.g001.model.Player;
import com.g001.util.CachedResourceLoader;

public class CurseAction extends Action {	

	
	private MessageAction message;
	private GCharacter character;
	private GCharacter opponent;
	private Image image;
	private float srcy = 600;
	
	private int damage;
	
	public CurseAction(final GCharacter character,GCharacter opponent){
		this.character = character;
		this.opponent = opponent;
		damage = bonus * BlockType.MAGIC_DEL.getPoints();		
		image = CachedResourceLoader.getInstance().getImage("data/g001/backgroundAction.png").getSubImage(0,200,512,100).getScaledCopy(2);
		image.rotate(90f);
		type = BlockType.MAGIC_DEL;
	}
	
	@Override
	public void render(GameContainer container, StateBasedGame game, Graphics g)
			throws SlickException {
//		if(character instanceof Player) {
//			// opponent
//			g.setClip(container.getWidth()-200,200,200,400);
//			image.draw(2*image.getHeight() ,srcy);
//			g.clearClip();
//		} else {
//			// player
//			g.setClip(0,200,200,400);
//			image.draw(-2*image.getHeight(),srcy);
//			g.clearClip();
//		}
		message.render(container, game, g);
	}

	@Override
	public void update(GameContainer container, StateBasedGame game, int delta)
			throws SlickException {
		srcy -=1.5*delta;
		message.update(container, game, delta);
	}

	@Override
	public void action() {
		message = new MessageAction("-"+damage+" of Magic", (character instanceof Player? MessagePositionType.RIGHT:MessagePositionType.LEFT));
		character.setCurrentAnimation(character.getCharacterType().getCurseAnim());
		opponent.addAction(new CursedAction(opponent, character, damage));
		message.action();
		opponent.getMagic().remove(damage);
	}
	
	@Override
	public void setBonus(final int bonus){
		this.bonus = bonus;
		damage *= bonus;
	}

	@Override
	public boolean isFinished() {
		return message.isFinished();
	}

}
